package com.rowenci.iot_agriculture.service.impl;

import com.rowenci.iot_agriculture.bean.Greenhouse;
import com.rowenci.iot_agriculture.mapper.GreenhouseDao;
import com.rowenci.iot_agriculture.service.api.GreenhouseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

/**
 * <p>
 *
 * </p>
 *
 * @author rowenci
 * @date 2019/4/21 17:39
 */
@Service
public class GreenhouseImpl implements GreenhouseService {

    @Resource
    GreenhouseDao greenhouseDao;

    @Override
    public List<Greenhouse> findAll() {
        return greenhouseDao.findAll();
    }

    @Override
    public Optional<Greenhouse> findById(Integer id) {
        return greenhouseDao.findById(id);
    }

    @Override
    public Greenhouse findByNumber(Integer number) {
        return greenhouseDao.findByNumber(number);
    }

    @Override
    public void updateIlluminanceByHouse_id(Integer house_id, Integer illuminance) {
        greenhouseDao.updateIlluminanceByHouse_id(house_id, illuminance);
    }

    @Override
    public void updateTemphumiByHouse_id(Integer house_id, Integer tempature, Integer humidity) {
        greenhouseDao.updateHumidityByHouse_id(house_id, humidity);
        greenhouseDao.updateTempatureByHouse_id(house_id, tempature);
    }

    @Override
    public void updateVegetableByHouse_id(Integer house_id, String vegetable) {
        greenhouseDao.updateVegetableByHouse_id(house_id, vegetable);
    }

    @Override
    public void addGreenHouse(Greenhouse greenhouse) {
        greenhouseDao.save(greenhouse);
    }

    @Override
    public boolean delByHouse_id(Integer house_id) {
        greenhouseDao.deleteById(house_id);
        return true;
    }

}
